package message

// web service 和前端通信错误码信息
// 分为下面几类

// user.*    用户模块
// project.* 项目模块
// task.*    任务模块

var messages = map[string]struct {
	code int
	msg  string
}{
	// api.* api模块
	"account.verification.code.success": {0, "验证码发送成功"},
	"account.verification.code.fail":    {1000, "验证码发送失败"},
	"account.verification.code.limit":   {1001, "验证码发送太频繁"},
	"account.verification.code.error":   {1002, "手机验证码不正确"},
	"account.mobile.number.illegal":     {1003, "手机号码格式不正确"},
	// user.* 用户模块
	"user.register.success":               {0, "用户注册成功"},
	"user.register.fail":                  {2001, "用户注册失败"},
	"user.username.already.exists":        {2002, "用户名已存在"},
	"user.username.format.incorrect":      {2003, "用户名格式不正确"},
	"user.mobile.already.exists":          {2004, "手机号码已存在"},
	"user.mobile.verification.code.error": {2005, "手机验证码错误"},
	"user.data.verification.error":        {2006, "数据验证错误"},

	"user.login.success":                     {0, "用户登录成功"},
	"user.login.not.login":                   {2100, "用户未登录"},
	"user.login.fail":                        {2101, "用户登录失败"},
	"user.login.fail.data.error":             {2102, "用户登录失败，数据验证错误"},
	"user.login.fail.disable":                {2103, "用户登录失败，请联系管理员"},
	"user.login.fail.name.or.password.error": {2104, "用户登录失败，用户名或密码错误"},
	"user.account.not.exists":                {2105, "用户不存在，请注册"},
	"user.account.password.error":            {2106, "密码错误"},
	"user.account.disabled":                  {2107, "账户权限受限，请联系管理员"},

	"user.logout.success": {0, "用户退出登录成功"},

	"user.info.update.success":   {0, "用户信息更新成功"},
	"user.info.update.fail":      {2200, "用户信息更新失败"},
	"user.avatar.update.success": {0, "用户头像更新成功"},

	"user.real.not.provide":       {2300, "用户真实信息未提供"},
	"user.real.need.complete":     {2301, "请先完成用户实名认证"},
	"user.real.is.checking":       {2302, "实名认证信息正在审核中"},
	"user.profile.not.incomplete": {2400, "用户信息不完善"},
	"user.profile.need.complete":  {2401, "请先完善用户个人信息"},

	"user.balance.get.fail":       {2500, "用户账目信息获取失败"},
	"user.balance.name.not.match": {2501, "用户提现账户名与实名认证信息不一致"},

	"user.balance.apply.success": {0, "用户提现申请成功，审核成功后将自动转入提现账户"},
	"user.balance.apply.fail":    {2600, "用户提现申请失败"},

	"user.password.update.success": {0, "用户密码修改成功"},
	"user.password.update.fail":    {2700, "用户密码修改失败"},

	"user.query.fail": {2800, "用户查询失败"},

	"user.create.success": {0, "用户创建成功"},
	"user.create.fail":    {2900, "用户创建失败"},

	"user.right.create.success": {0, "用户权限创建成功"},
	"user.right.create.fail":    {3000, "用户权限创建失败"},

	"user.right.update.success": {0, "用户权限更新成功"},
	"user.right.update.fail":    {3000, "用户权限更新失败"},

	// project.* 项目模块
	"project.get.success":                   {0, "项目获取成功"},
	"project.post.success":                  {0, "提交项目成功"},
	"project.get.fail":                      {4001, "项目获取失败"},
	"project.get.fail.other":                {4002, "项目获取失败，其他错误"},
	"project.get.fail.authenticate.failure": {4003, "项目获取失败，认证失败"},
	"project.get.fail.no.permission":        {4004, "项目获取失败，没有权限"},
	"project.post.fail.pharse.data":         {4005, "提交项目失败,数据解析出错"},
	"project.post.fail.illegal.data":        {4006, "提交项目失败，数据校验错误"},
	"project.post.fail":                     {4007, "提交项目失败，提交时出错"},
	"project.get.simple.file.fail":          {4008, "获取文件列表失败"},

	// task.* 任务模块
	"task.get.success":                   {0, "任务获取成功"},
	"task.get.fail":                      {5001, "任务获取失败"},
	"task.get.fail.authenticate.failure": {5002, "任务获取失败，认证失败"},
	"task.get.fail.no.permission":        {5003, "任务获取失败，没有权限"},
	"task.get.fail.no.more.task":         {5004, "任务获取失败，没有任务了"},

	"task.post.success":                   {0, "任务提交成功"},
	"task.post.fail":                      {6001, "任务提交失败"},
	"task.post.fail.illegal.data":         {6002, "任务提交失败，数据校验失败"},
	"task.post.fail.authenticate.failure": {6003, "任务提交失败，认证失败"},
	"task.post.fail.other.reasons":        {6004, "任务提交失败，其他错误"},

	"task.review.get.fail": {7002, "任务获取失败"},

	"task.review.post.success":           {0, "任务提交成功"},
	"task.review.post.fail":              {8001, "任务提交失败"},
	"task.review.post.fail.illegal.data": {8002, "任务提交失败，数据校验失败"},
}

type ErrMsg struct {
	Code int    `json:"code"`
	Msg  string `json:"message"`
}

func ErrMsgFor(key string) ErrMsg {
	return ErrMsg{messages[key].code, messages[key].msg}
}
